package com.tanjun.common.exception;

import lombok.Getter;

/**
 * 业务异常
 */
@Getter
public class BizException extends RuntimeException {
    private ErrCode errCode;
    private String message;

    public BizException(ErrCode errCode) {
        this.errCode = errCode;
        this.message = errCode.getMessage();
    }

    public BizException(ErrCode errCode, String msg) {
        this.errCode = errCode;
        this.message = msg;
    }

    public BizException(String msg) {
        this.message = msg;
    }

    public Integer getCode() {
        if (errCode == null) {
            return 500;
        }
        Integer code = 500;
        try {
            code = Integer.valueOf(errCode.getErrCode());
        }
        catch (Exception e) {

        }
        return code;
    }
}
